/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegistrarEleccion.java
 *
 * Created on 14/11/2010, 01:45:26 AM
 */

package zonasoft.Vistas.Funcionales;
import com.mysql.jdbc.Connection;
import java.awt.Dimension;
import java.awt.Point;
import zonasoft.Utilidades.Control;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import zonasoft.Conceptos.Candidato;
import zonasoft.Manejadores.ManejadorBaseDatos;
import zonasoft.Manejadores.ManejadorEleccion;
import zonasoft.Conceptos.Eleccion;
import zonasoft.Conceptos.Especiales.Barrio;
import zonasoft.Manejadores.ManejadorCandidato;
import zonasoft.Manejadores.ManejadorLider;
import zonasoft.Manejadores.ManejadorLugar;
import zonasoft.Manejadores.ManejadorZonificados;
import zonasoft.Vistas.Negocio.RegistrarZonificado;
import zonasoft.Vistas.VentanaPrincipal;
/**
 *
 * @author JORGE
 */
public class RegistrarCandidato extends javax.swing.JDialog {

 HashMap<String, Integer> elecciones;
    HashMap<String, Integer> departamentos;
    HashMap<String, Integer> municipios;
    HashMap<String, Integer> zonas;
    HashMap<String, Integer> puestos;
      HashMap<String, Integer> localidades;
    HashMap<String, Integer> unidades;
    HashMap<String, Integer> barrios;
//    List<Puesto> puestosActuales = new ArrayList<Puesto>();
//    List<Zona> zonaActual = new ArrayList<Zona>();
    List<Barrio> barrioActual = new ArrayList<Barrio>();
//    List<Departamentos> departamentosActuales = new ArrayList<Departamentos>();
//    List<Municipios> municipiosActuales = new ArrayList<Municipios>();
    private HashMap<String, String> puestos2;
//    HashMap<String,Integer> elecciones;
    /** Creates new form RegistrarEleccion */
     public RegistrarCandidato(JFrame parent) {  //
        super(parent,true);
        initComponents();
        pack();
        Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));
        checkboxS.setSelected(true);
//        System.out.println(RegistrarCan);
         
        listaraBarrios();
    }
Candidato ca = null;
ManejadorCandidato mc = new ManejadorCandidato();


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanelElecciones1 = new org.jdesktop.swingx.JXPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        campoNombre = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoIdCandidato = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        campoApellido = new javax.swing.JTextField();
        campotelefono = new javax.swing.JTextField();
        comboEleccion = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        campoDireccion = new javax.swing.JTextArea();
        jLabel13 = new javax.swing.JLabel();
        campoCorreo = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        checkboxN = new javax.swing.JCheckBox();
        checkboxS = new javax.swing.JCheckBox();
        jLabel17 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        campoLocalidad = new javax.swing.JTextField();
        uComuneraDeGov = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        comboBarrioPorBarrio = new javax.swing.JComboBox();
        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        botonGuardar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        botonLimpiar = new javax.swing.JButton();

        setTitle("");

        jXPanelElecciones1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.black, java.awt.Color.darkGray), "Datos Personales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 2, 18))); // NOI18N

        jLabel7.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel7.setText("Eleccion");

        jLabel8.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel8.setText("Apellidos");

        campoNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoNombreKeyTyped(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel11.setText("Identificacion");

        campoIdCandidato.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoIdCandidatoKeyTyped(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel9.setText("Nombre");

        jLabel12.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel12.setText("Telefono");

        listararEleccion();

        jLabel14.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel14.setText("Direccion");

        campoDireccion.setColumns(20);
        campoDireccion.setRows(5);
        campoDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoDireccionKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(campoDireccion);

        jLabel13.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel13.setText("Correo");

        campoCorreo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoCorreoKeyTyped(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel10.setText("Hoja de Vida");

        checkboxN.setText("No");
        checkboxN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkboxNActionPerformed(evt);
            }
        });

        checkboxS.setText("Si");
        checkboxS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkboxSActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel17.setText("Barrio");

        jLabel15.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel15.setText("Localidad");

        campoLocalidad.setEditable(false);

        uComuneraDeGov.setEditable(false);

        jLabel16.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel16.setText("U.Comunera.G");

        comboBarrioPorBarrio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBarrioPorBarrioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanelElecciones1Layout = new javax.swing.GroupLayout(jXPanelElecciones1);
        jXPanelElecciones1.setLayout(jXPanelElecciones1Layout);
        jXPanelElecciones1Layout.setHorizontalGroup(
            jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel11)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanelElecciones1Layout.createSequentialGroup()
                            .addComponent(jLabel7)
                            .addGap(38, 38, 38)))
                    .addComponent(jLabel9)
                    .addComponent(jLabel13)
                    .addComponent(jLabel10)
                    .addComponent(jLabel14))
                .addGap(20, 20, 20)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                        .addComponent(checkboxS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(checkboxN))
                    .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                        .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoCorreo, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                            .addComponent(campoNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                            .addComponent(campoIdCandidato, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                            .addComponent(comboEleccion, 0, 204, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
                        .addGap(45, 45, 45)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8)
                                .addComponent(jLabel12))
                            .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addGap(39, 39, 39)))
                        .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                            .addComponent(jLabel15)
                            .addGap(16, 16, 16)))
                    .addComponent(jLabel16))
                .addGap(4, 4, 4)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(uComuneraDeGov, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoLocalidad, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campotelefono, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoApellido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                    .addComponent(comboBarrioPorBarrio, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jXPanelElecciones1Layout.setVerticalGroup(
            jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(comboEleccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(campoIdCandidato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(campotelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                            .addComponent(jLabel13)
                            .addGap(3, 3, 3)))
                    .addComponent(campoCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(checkboxS)
                        .addComponent(checkboxN))
                    .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel17))
                    .addComponent(comboBarrioPorBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanelElecciones1Layout.createSequentialGroup()
                        .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(campoLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jXPanelElecciones1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16)
                            .addComponent(uComuneraDeGov, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel14)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jLabel1.setFont(new java.awt.Font("Vani", 1, 18));
        jLabel1.setText("Registro de Candidato");
        jXTaskPaneContainer1.add(jLabel1);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.gray, java.awt.Color.lightGray));

        botonGuardar.setFont(new java.awt.Font("Lucida Bright", 1, 12));
        botonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/Floppy-icon.png"))); // NOI18N
        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonCancelar.setFont(new java.awt.Font("Lucida Bright", 1, 12));
        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/Delete-icon.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        botonLimpiar.setFont(new java.awt.Font("Lucida Bright", 1, 12));
        botonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/limpiar.png"))); // NOI18N
        botonLimpiar.setText("Limpiar");
        botonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonLimpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(botonLimpiar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                    .addComponent(botonCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                    .addComponent(botonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(botonGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonCancelar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.DEFAULT_SIZE, 855, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXPanelElecciones1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jXPanelElecciones1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
////////public boolean revision(){
////////  boolean estado = false;
////////                ManejadorBaseDatos manejabd = ManejadorBaseDatos.getInstancia();
////////                  try {
////////                    manejabd.conectar();
////////                    ManejadorCandidato.con=manejabd.getConexion();
////////                     Candidato can = new Candidato();
////////                    String nombreEleccion=comboEleccion.getSelectedItem().toString();
////////                    Integer idEleccionSelecionada=elecciones.get(nombreEleccion);
////////                    String id = (String.valueOf( idEleccionSelecionada));
////////
////////                     can = ManejadorCandidato.getCandidatoE(id);
////////                     if (can != null){
////////                          estado = true;
////////                          }else{
////////                             //JOptionPane.showMessageDialog(null," Esta Eleccion no Tiene Candidato Asociado", "Busqueda sin resultados",JOptionPane.INFORMATION_MESSAGE);
////////                          estado = false;
////////                          }
////////                   } catch (Exception ex) {
////////            // Logger.getLogger(ConsultaEleccion.class.getName()).log(Level.SEVERE
////////                  }
////////  return estado;
////////}
 ManejadorLider ml = new ManejadorLider();
   ManejadorZonificados mz = new ManejadorZonificados();
    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed
        // TODO add your handling code here:
        ManejadorBaseDatos mb = ManejadorBaseDatos.getInstancia();
         if(comboEleccion.getSelectedItem().toString().isEmpty()){
                JOptionPane.showMessageDialog(null, "el campo id Eleccion esta vacio", "error",JOptionPane.WARNING_MESSAGE);
            }else if(campoIdCandidato.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "el campo identificacion esta vacio", "error",JOptionPane.WARNING_MESSAGE);
            }
            else if(campoNombre.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "el campo nombre esta vacio", "error",JOptionPane.WARNING_MESSAGE);
            }else if(campoApellido.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "el campo nombre esta vacio", "error",JOptionPane.WARNING_MESSAGE);
            }
//            else if(campoprofesion.getText().isEmpty()){//                JOptionPane.showMessageDialog(null, "el campo profesion esta vacio", "error",JOptionPane.WARNING_MESSAGE);//            }
            else if(campotelefono.getText().isEmpty()){
                JOptionPane.showMessageDialog(null,"el campo telefono esta vacio", "error", JOptionPane.WARNING_MESSAGE);
         } else if (comboBarrioPorBarrio.getSelectedIndex()==0) {
                JOptionPane.showMessageDialog(null, "el barrio no ha sido seleccionado", "error",JOptionPane.WARNING_MESSAGE);
            }else{

        try {
            mb.conectar();
            ManejadorCandidato.con =mb.getConexion();
            ManejadorZonificados.con=mb.getConexion();
//             ManejadorCandidato.con = mb.getConexion();
            if(mc.getCandidato(campoIdCandidato.getText())!=null){
                JOptionPane.showMessageDialog(null, "Este candidato ya esta registrada \n Intente Nuevamente", "Novedad",JOptionPane.ERROR_MESSAGE);
            }
            else if(mc.getLiderPropio(campoIdCandidato.getText()) != null) {
                    JOptionPane.showMessageDialog(null, "Este Candidato esta registrado Como lider \n Anuncie Novedad Escrita al Administrador", "Novedad", JOptionPane.WARNING_MESSAGE);
                }
            else if(mz.getZonificadosPropio(campoIdCandidato.getText()) != null) {
                    JOptionPane.showMessageDialog(null, "Este Candidato esta registrado Como zonificado \n Anuncie Novedad Escrita al Administrador", "Novedad", JOptionPane.WARNING_MESSAGE);
                    System.out.println("si entro aca");
            }
            else{
//                if( revision() != true){
                String nombreEleccion=comboEleccion.getSelectedItem().toString();
                Integer idEleccionSelecionada=elecciones.get(nombreEleccion);

                ca = new Candidato();
                ca.setIdEleccion(String.valueOf(idEleccionSelecionada));
                ca.setIdCandidato(campoIdCandidato.getText());
                ca.setNombre(campoNombre.getText());
                ca.setApellido(campoApellido.getText());
                ca.setCorreo(campoCorreo.getText());
//                ca.setProfesion(campoprofesion.getText());
                ca.setTelefono(campotelefono.getText());
                int  hoja = 0;
                  if(checkboxS.isSelected()){
                   hoja=1;
                  }
                ca.setHojaVida(hoja);
                 ca.setBarrio((String) comboBarrioPorBarrio.getSelectedItem());
                   ca.setDireccion(campoDireccion.getText());
//                ca.setBarrio(comboBarrio.getSelectedItem().toString());
                mc.crearCandidato(ca);
                JOptionPane.showMessageDialog(null," Candidato Registrado exitosamente!", "Informacion",JOptionPane.INFORMATION_MESSAGE);
                limpiar();
//                }else{
//               JOptionPane.showMessageDialog(null," Esta Eleccion ya ha sido registrada a otro candidato!", "Informacion",JOptionPane.ERROR_MESSAGE);
//                }
            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarCandidato.class.getName()).log(Level.SEVERE, null, ex);
        }
            }
         

    }//GEN-LAST:event_botonGuardarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        // TODO add your handling code here:
        int resp = JOptionPane.showConfirmDialog(this, "Seguro que deseas cerrar la Ventana ","Warning", JOptionPane.YES_NO_OPTION);
        if(resp == JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_botonCancelarActionPerformed

    private void campoDireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDireccionKeyTyped
        // TODO add your handling code here:
        Control.validaCantidadA(evt, campoDireccion, 45);
}//GEN-LAST:event_campoDireccionKeyTyped

    private void campoCorreoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCorreoKeyTyped
        // TODO add your handling code here:
        Control.validaCorreo(evt, campoCorreo, 45);
}//GEN-LAST:event_campoCorreoKeyTyped

    private void checkboxSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkboxSActionPerformed
        // TODO add your handling code here:
        checkboxN.setSelected(false);
        
    }//GEN-LAST:event_checkboxSActionPerformed

    private void checkboxNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkboxNActionPerformed
        // TODO add your handling code here:
        checkboxS.setSelected(false);
    }//GEN-LAST:event_checkboxNActionPerformed

    private void botonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonLimpiarActionPerformed
        // TODO add your handling code here:
        limpiar();
    }//GEN-LAST:event_botonLimpiarActionPerformed
    private void comboBarrioPorBarrioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBarrioPorBarrioActionPerformed
        // TODO add your handling code here:
       // listaraBarrios();
        listaraLocalidadPorBarrio();
}//GEN-LAST:event_comboBarrioPorBarrioActionPerformed

    private void campoIdCandidatoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoIdCandidatoKeyTyped
        // TODO add your handling code here:
        Control.validaNumeros(evt, campoCorreo, 10);
    }//GEN-LAST:event_campoIdCandidatoKeyTyped

    private void campoNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoNombreKeyTyped
        // TODO add your handling code here:
        Control.validaLetras(evt, campoNombre, 44);
    }//GEN-LAST:event_campoNombreKeyTyped
   
   
 public void listaraLocalidadPorBarrio() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        localidades = new HashMap<String, Integer>();
        String[] datos = new String[2];
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
          if (comboBarrioPorBarrio.getItemCount() > 0 && comboBarrioPorBarrio.getSelectedIndex()!=0) {
                String nombreBarrio = comboBarrioPorBarrio.getSelectedItem().toString();

                Integer idBa = barrios.get(nombreBarrio);
               // System.out.println("idBa = " + idBa);
                datos = ManejadorLugar.getDatosLugar(String.valueOf(idBa));
//           Localidad loc = null;
//               while (iter.hasNext()){
//           loc = iter.next();
//           int codigo = Integer.parseInt(datos[2]);
//           comboLocalidad.addItem(datos[0]);  en el combo se le pone el nombre de este metodo
                campoLocalidad.setText(datos[0]);
                uComuneraDeGov.setText(datos[1]);
           }
//            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar localidades
    
    public void listaraBarrios() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        barrios = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboBarrioPorBarrio.removeAllItems();

            List listarBarrio = null;
            listarBarrio = ManejadorLugar.listarBarrios();

            barrioActual = listarBarrio;
            Iterator<Barrio> iter = listarBarrio.iterator();
            Barrio bar = null;
            comboBarrioPorBarrio.addItem("-- Seleccione un Barrio --");
            while (iter.hasNext()) {
                bar = iter.next();
                int idBarrio = Integer.parseInt(bar.getIdBarrio());
                comboBarrioPorBarrio.addItem(bar.getNombre());
                barrios.put(bar.getNombre(), idBarrio);
//                System.out.println("bar.getNombre() = " + bar.getNombre());
            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarCandidato.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

     private void limpiar() {
    //comboEleccion.setSelectedItem(jLabel1)
    campoNombre.setText("");
   campoApellido.setText("");
   checkboxS.setSelected(true);
     campoCorreo.setText("");
   campoIdCandidato.setText("");
   campotelefono.setText("");
   comboBarrioPorBarrio.setSelectedIndex(0);
   comboEleccion.setSelectedIndex(0);
   campoDireccion.setText("");
campoLocalidad.setText("");
uComuneraDeGov.setText("");
    }
          // PARA EL COMBO BOX

public void listararEleccion()  {
    ManejadorBaseDatos mbd=ManejadorBaseDatos.getInstancia();
     elecciones=new HashMap<String,Integer>();
         try{
               mbd.conectar();
               ManejadorEleccion.con = mbd.getConexion();
               comboEleccion.removeAllItems();
               //ManejadorEleccion.listarElecciones();

            List listarElecciones = null;
      //   listarpaises = ManejadorPais.getlistaPais();
         listarElecciones = ManejadorEleccion.listarElecciones();
            Iterator<Eleccion> iter = listarElecciones.iterator();
            Eleccion e = null;
            while (iter.hasNext()) {
                e = iter.next();
                int idEleccion=Integer.parseInt(e.getIdEleccion());
                comboEleccion.addItem(e.getNombre());
                elecciones.put(e.getNombre(),idEleccion);
            }
         }catch (Exception ex){
            ex.printStackTrace();
         }

         }



// PARA EL COMBO BOX
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JButton botonLimpiar;
    private javax.swing.JTextField campoApellido;
    private javax.swing.JTextField campoCorreo;
    private javax.swing.JTextArea campoDireccion;
    private javax.swing.JTextField campoIdCandidato;
    private javax.swing.JTextField campoLocalidad;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campotelefono;
    private javax.swing.JCheckBox checkboxN;
    private javax.swing.JCheckBox checkboxS;
    private javax.swing.JComboBox comboBarrioPorBarrio;
    private javax.swing.JComboBox comboEleccion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXPanel jXPanelElecciones1;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private javax.swing.JTextField uComuneraDeGov;
    // End of variables declaration//GEN-END:variables

//    public static void main(String arg[]){
//     RegistrarCandidato e = new RegistrarCandidato();
//    e.setVisible(true);
//    }

}
